{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1db87959",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from PIL import Image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8895800c",
   "metadata": {},
   "outputs": [],
   "source": [
    "root_dir=\"../AID\"\n",
    "label_list=os.listdir(root_dir)\n",
    "img_class_dir=os.path.join(root_dir,label_list[0])\n",
    "img_list=os.listdir(img_class_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3b29d91c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=600x600 at 0x24EF9BF3AC8>\n"
     ]
    }
   ],
   "source": [
    "img_path=os.path.join(img_class_dir,img_list[0])\n",
    "img=Image.open(img_path)\n",
    "img.show()\n",
    "print(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "af3b1522",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=600x600 at 0x24EF9CA5128>\n"
     ]
    }
   ],
   "source": [
    "img_path=os.path.join(img_class_dir,img_list[1])\n",
    "img=Image.open(img_path)\n",
    "img.show()\n",
    "print(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "151e4f12",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=600x600 at 0x24EF9CA52E8>\n"
     ]
    }
   ],
   "source": [
    "img_path=os.path.join(img_class_dir,img_list[4])\n",
    "img=Image.open(img_path)\n",
    "img.show()\n",
    "print(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "03475392",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "360\n",
      "310\n",
      "220\n",
      "400\n",
      "360\n",
      "260\n",
      "240\n",
      "350\n",
      "410\n",
      "300\n",
      "370\n",
      "250\n",
      "390\n",
      "280\n",
      "290\n",
      "340\n",
      "350\n",
      "390\n",
      "370\n",
      "420\n",
      "380\n",
      "260\n",
      "290\n",
      "410\n",
      "300\n",
      "300\n",
      "330\n",
      "290\n",
      "360\n",
      "420\n"
     ]
    }
   ],
   "source": [
    "img_num=[]\n",
    "for i in range(len(label_list)):\n",
    "    img_class_dir=os.path.join(root_dir,label_list[i])\n",
    "    img_list=os.listdir(img_class_dir)\n",
    "    print(len(img_list))\n",
    "    img_num.append(len(img_list))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "98f8bd5e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "item=670\n",
    "length=0\n",
    "label_index=0\n",
    "for i in range(30):\n",
    "    length=length+img_num[i]\n",
    "    if item<length:\n",
    "        label_index=i\n",
    "        break\n",
    "print(label_index)\n",
    "print(item-length+img_num[label_index])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43d284d7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10d35981",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "352db06c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:AI] *",
   "language": "python",
   "name": "conda-env-AI-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
